<?php

namespace App\Http\Controllers;

use App\Models\Disclosure;
use App\Services\DisclosureService;
use Illuminate\Http\Request;

class DisclosureController extends Controller
{
    protected $DisclosureService;
    public function __construct(DisclosureService $DisclosureService)
    {
        $this->DisclosureService = $DisclosureService;
    }

    public function index(Request $Request) {
        $search = $Request->search;
        $sql = $this->DisclosureService->getType($search);
        $sql->with('disclosures')->where('project_id',$Request->project_id);
        $total = $sql->count();
        $data = $sql->orderBy('created_at','desc')->get();
        return response()->json(['code' => '200', 'msg' => '操作成功','total'=>$total,'data'=>$data]);
    }

    public function show(Request $Request) {
        if(!$Request->id){
            return response()->json(['code' => '403', 'msg' => '参数错误']);
        }
        $data = Disclosure::where('id',$Request->id)->first();
        return response()->json(['code' => '200', 'msg' => '操作成功','data'=>$data]);
    }
}
